package BehaviorModel.iterorModel;

import java.util.ArrayList;
import java.util.Iterator;

public class ClientTest {
    public static void main(String[] args) {
        Department[] departments = new Department[3];
        departments[0] = new Department("部门1","部门描述1");
        departments[1] = new Department("部门2","部门描述2");
        departments[2] = new Department("部门3","部门描述3");


        ComputerCollege computerCollege = new ComputerCollege(departments);
        computerCollege.removeDepartment(departments[2]);

        System.out.println("======================================="+computerCollege.getName()+"删除前");
        Iterator iteror = computerCollege.createIterator();
        while (iteror.hasNext()){
            Department next =(Department) iteror.next();
            System.out.println(next);
        }

        computerCollege.addDepartment(new Department("部门4","部门描述4"));
        computerCollege.addDepartment(new Department("部门5","部门描述5"));
        System.out.println("======================================="+computerCollege.getName()+"添加后");

        while (iteror.hasNext()){
            Department next =(Department) iteror.next();
            System.out.println(next);
        }


        // 逆序
        ComputerReserveCollege computerReserveCollege = new ComputerReserveCollege(departments);
        System.out.println(computerReserveCollege.getName());
        computerReserveCollege.createIterator().forEachRemaining(System.out::println);


        ArrayList<Department> departmentsList = new ArrayList<>();
        departmentsList.add(new Department("部门1","部门描述1"));
        departmentsList.add(new Department("部门2","部门描述2"));
        departmentsList.add(new Department("部门3","部门描述3"));
        Department e = new Department("部门4",
                                      "部门描述4");
        departmentsList.add(    e);
        InfoCollege infoCollege = new InfoCollege(departmentsList);
        System.out.println("======================================="+infoCollege.getName());
        //InfoIteror infoIteror = new InfoIteror(departmentsList);
        //while (infoIteror.hasNext()){
        //    Department next = (Department)infoIteror.next();
        //    System.out.println(next);
        //}

        Iterator iterator = infoCollege.createIterator();
        System.out.println("删除前");
        //iterator.forEachRemaining(System.out::println);

        while ( iterator.hasNext()) {
            Department next = (Department) iterator.next();
            System.out.println(next);
        }
        infoCollege.removeDepartment(e);
        System.out.println("删除后");
        //iterator.forEachRemaining(System.out::println);

        while ( iterator.hasNext()) {
            Department next = (Department) iterator.next();
            System.out.println(next);
        }

        InfoReserveCollege infoReserveCollege = new InfoReserveCollege(departmentsList);
        System.out.println(infoReserveCollege.getName());
        infoReserveCollege.createIterator().forEachRemaining(System.out::println);

    }
}
